package com.mjlf.mr.speed;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName: SpeedReduce
 * @Author: majun
 * @CreateDate: 2018/12/19 9:40
 * @Version: 1.0
 * @Description: TODO
 */

public class SpeedReduce extends Reducer<Speed, Text, Text, NullWritable> {

    @Override
    protected void reduce(Speed key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        int flag = 0;
        String carN = "";
        for (Text index : values) {
            if (flag == 0) {
                carN = index.toString().substring(20, 26);
                context.write(index, NullWritable.get());
                flag++;
            } else {
                String indexCarN = index.toString().substring(20, 26);
                if (indexCarN.equals(carN)) {
                    continue;
                } else {
                    context.write(index, NullWritable.get());
                    break;
                }
            }
        }
    }
}